import time
from selenium import webdriver
from selenium.webdriver.edge.service import Service
from selenium.webdriver.common.by import By
from webdriver_manager.microsoft import EdgeChromiumDriverManager

# 关键修改：指定国内镜像源（淘宝镜像）
EdgeIns = EdgeChromiumDriverManager(
    url="https://npm.taobao.org/mirrors/edgedriver/"  # 国内镜像地址
).install()

# 创建Edge浏览器驱动对象
driver = webdriver.Edge(service=Service(EdgeIns))
time.sleep(2)

# 访问百度
driver.get("https://www.baidu.com")
time.sleep(2)

# 搜索操作
driver.find_element(By.CSS_SELECTOR, "#kw").send_keys("迪丽热巴")
driver.find_element(By.CSS_SELECTOR, "#su").click()
time.sleep(2)

# 关闭浏览器
driver.quit()
